(function (_super) {
    var io = ppt.io;
    var curDirection = null;

    function GameUI(data) {
        GameUI.super(this);

        this.rocker = null;
        this.skillPanel = null;
        this.roleInfo = null;
        this.timer = null;
        this.plane = null;
        this.propTip = null;
        this.beforeGame = null;
        this.monsterInfo = null;
        this.rebornTimer = null;
        this.btnExit = null;

        this.init(data);
    }
    Laya.class(GameUI, "Game.UI", _super);
    var _proto = GameUI.prototype;
    _proto.destroy = function () {
        io.unregister("role::crazy", this.addRoleCrazyTip);

        _super.prototype.destroy.call(this, true);

        this.rocker = null;
        this.skillPanel = null;
        this.roleInfo = null;
        this.timer = null;
        this.plane = null;
        this.propTip = null;
        this.beforeGame = null;
        this.monsterInfo = null;
        this.rebornTimer = null;
        this.btnExit = null;
    }

    _proto.init = function (data) {
        io.register("role::crazy", this, this.addRoleCrazyTip);

        this.size(GAME_CONFIG.WIDTH, Laya.stage.height);
        this.battleId = data.battleId;

        if(data.mode == "pve"){
            this.createPVEUI(data);
        }

        this.createCommonUI(data);
    }
    _proto.createCommonUI = function (data) {
        var roles = data.roles;
        for(var i in roles){
            if(roles[i].userId == userId){
                this.skillPanel = new Game.Skill(roles[i], this.battleId);
            }
        }

        this.beforeGame = new Game.BeforeGame();
        this.roleInfo = new Game.RoleInfo(roles);
        this.timer = new Game.Timer(data.mode, data.time);
        this.plane = new Game.Plane();
        this.propTip = new Game.PropTip();

        var rocker = new Game.Rocker("blue", {x : 80, bottom : 65});
            rocker.on("moving", this, function (data) {
                if(curDirection){
                    if(curDirection != data.direction){
                        io.emit({cmd:'move::go',params : {direction : data.direction, battleId : this.battleId}});
                    }
                }else{
                    io.emit({cmd:'move::go',params : {direction : data.direction, battleId : this.battleId}});
                }
                curDirection = data.direction;
            });
            rocker.on("reset", this, function () {
                io.emit({cmd:'move::stop',params : {direction : curDirection, battleId : this.battleId}});
                curDirection = null;
            });
        this.rocker = rocker;

        this.addChildren(this.rocker, this.skillPanel, this.roleInfo, this.timer, this.plane, this.propTip, this.beforeGame);
    }
    _proto.createPVEUI = function (data) {
        var btnExit = new Laya.Button("res/game/ui/btn_exit.png");
            btnExit.stateNum = 1;
            btnExit.right = 20;
            btnExit.y = 25;
            btnExit.on(Laya.Event.CLICK, this, function () {
                ppt.director.popScene(new Alert.Exit, {shadowAlpha : 0.7});
            });

        this.btnExit = btnExit;
        this.rebornTimer = new Game.RebornTimer();
        this.monsterInfo = new Game.MonsterInfo(data.boss);
        this.addChildren(this.monsterInfo, this.rebornTimer, btnExit);
    }
    _proto.addRoleCrazyTip = function () {
        this.addChild(new Game.Tips("进入暴走模式"));
    }

    _proto.enter = function () {
        console.log("Game Scene Enter. UIPanel enter");
        this.roleInfo.enter();
    }

    _proto.resize = function (height) {
        this.height = height;

        this.rocker.resize(height);
        this.skillPanel.resize(height);
        this.plane.resize(height);
        this.rebornTimer && this.rebornTimer.resize(height);
    }
})(Laya.Sprite);